home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / HighlightFilter.java < prev    next >
Text File  |  1998-09-15  |  3KB  |  82 lines

  1. /*
  2.  * @(#)HighlightFilter.java    1.6 98/03/18
  3.  *
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. import java.applet.Applet;
  32. import java.awt.Image;
  33. import java.awt.Graphics;
  34. import java.awt.Rectangle;
  35. import java.util.StringTokenizer;
  36. import java.util.Vector;
  37. import java.util.Hashtable;
  38. import java.net.URL;
  39. import java.awt.image.*;
  40. import java.net.MalformedURLException;
  41.  
  42. /**
  43.  * An image filter to highlight an image by brightening or darkening
  44.  * the pixels in the images.
  45.  *
  46.  * @author     Jim Graham
  47.  * @version     1.6, 03/18/98
  48.  */
  49. class HighlightFilter extends RGBImageFilter {
  50.     boolean brighter;
  51.     int percent;
  52.  
  53.     public HighlightFilter(boolean b, int p) {
  54.     brighter = b;
  55.     percent = p;
  56.     canFilterIndexColorModel = true;
  57.     }
  58.  
  59.     public int filterRGB(int x, int y, int rgb) {
  60.     int r = (rgb >> 16) & 0xff;
  61.     int g = (rgb >> 8) & 0xff;
  62.     int b = (rgb >> 0) & 0xff;
  63.     if (brighter) {
  64.         r = (255 - ((255 - r) * (100 - percent) / 100));
  65.         g = (255 - ((255 - g) * (100 - percent) / 100));
  66.         b = (255 - ((255 - b) * (100 - percent) / 100));
  67.     } else {
  68.         r = (r * (100 - percent) / 100);
  69.         g = (g * (100 - percent) / 100);
  70.         b = (b * (100 - percent) / 100);
  71.     }
  72.     if (r < 0) r = 0;
  73.     if (r > 255) r = 255;
  74.     if (g < 0) g = 0;
  75.     if (g > 255) g = 255;
  76.     if (b < 0) b = 0;
  77.     if (b > 255) b = 255;
  78.     return (rgb & 0xff000000) | (r << 16) | (g << 8) | (b << 0);
  79.     }
  80. }
  81.  
  82.